<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
          name="viewport">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>拍卖设置</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/page.css">
    <link rel="stylesheet" href="../css/lCalendar.css">
    <script src="../js/jquery-3.2.1.min.js"></script>
    <script src="../js/media.js"></script>
    <script src="../js/common.js"></script>
    <script src="../js/lCalendar.js"></script>
    <style>
        .section2 input {
            text-align: right;
            font-size:0.16rem;
        }
        input{
            border: none;
            background: #fff;
        }
        .checked {}
        .rate_int:after{
        		content:'%'
        }
    </style>
</head>

<body>
    <!--头部-->
    <div class="public-header flex">
        <!--<span class="public-header-left-search"></span>-->
        <span class="public-header-left-back"></span>
        <span class="public-header-center">拍卖设置</span>
        <span class="public-header-right">保存</span>
    </div>

    <!--正文-->
    <div class="Shop-settings bc-gray">
        <section class="section1">
            <ul>
                <li class="flex">
                    <span>店铺折扣</span>
                    <img id="check" on="0"  src="../img/选择%201@2x.png"  style="width: 40px;height: 20px;">

                    <!--<div class="checkbox checkbox-slider&#45;&#45;b-flat">-->
                        <!--<label>-->
				<!--<input type="checkbox" id="check"><span></span>-->
			<!--</label>-->
                    <!--</div>-->
                </li>

            </ul>
        </section>
        <p class="t1" style="text-align:right;">截止时间在折扣期内的，均享受折扣</p>
        <section class="section2">
            <ul>

                <li class="flex">
                    <span>折扣率</span>
                    <em class="rate_int" style="background:none;"><input type="text" placeholder="请填写折扣率" disabled="disabled" id="rate" maxlength="2" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></em>
               		
                </li>
                <li class="flex">
                    <span>开始时间</span>
                    <em>
                        <!-- <input type="text" placeholder="时间格式：xxxx-xx-xx" disabled="disabled" id="s_d"> -->
                        <input style="color: ; text-align: right;" class="weui-input weui-cell__ft" disabled="disabled" id="s_d" type="text" readonly="" name="input_date" placeholder="日期选择特效" data-lcalendar="2011-01-1,2020-12-31" />
                    </em>
                </li>
                <li class="flex">
                    <span>结束时间</span>
                    <em>
                            <!-- <input type="text" placeholder="时间格式：xxxx-xx-xx" disabled="disabled" id="e_d"> -->
                            <input style="color: ; text-align: right;" class="weui-input weui-cell__ft" disabled="disabled" id="e_d" type="text" readonly="" name="input_date" placeholder="日期选择特效" :data-lcalendar="2011-01-1,2020-12-31" />
                    </em>
                </li>

            </ul>
        </section>



    </div>




    <script>
        var  iskaiqi = 0;
        $(function () {
            var calendar = new lCalendar();
            calendar.init({
                'trigger': '#s_d',
                'type': 'date'
            });
            var calendardatetime = new lCalendar();
            calendardatetime.init({
                'trigger': '#e_d',
                'type': 'datetime'
            });
            //获取折扣信息
            $.ajax({
                url:base_url+"ZITAOHUI/store/msg/isDiscountRate",
                data:{
                    storeId:sessionStorage.getItem("s_id")
                },
                type:"post",
                dataType:"json",
                success:function (data){
                    if(data.code== 1){
                        console.log(data);
                        var _d = data.extend.date;
                        if(_d.is_discount_rate){
                            iskaiqi = 1;
//                            $("#rate").text(_d.discount_rate);
                            $('.section2 input').removeAttr('disabled');

                            $("#check").attr("src","../img/选择%202@2x.png");
                             $("#check").attr('on','1');
                            $("#s_d").val(getLocalTime(_d.start_time));
                            $("#e_d").val(getLocalTime(_d.end_time));
                            $("#rate").val(_d.discount_rate);

                        }


                    }
                }
            })


            $('#check').click(function () {
                var ons  = $(this).attr("on");
                if (ons == 0) {
                    $('.section2 input').removeAttr('disabled');
                    iskaiqi = 1;
                    $(this).attr('on','1');
                    $(this).attr("src","../img/选择%202@2x.png");
                } else {
                    $('.section2 input').attr('disabled', 'disabled')
                    iskaiqi = 0;
                    $(this).attr('on','0');
                    $(this).attr("src","../img/选择%201@2x.png");

                }
            })
//            alert("最新");
            $('.public-header-right').click(function () {
//                alert("23333");
                if(iskaiqi == 1){
                    if($('#s_d').val() == ''){
                        alert("请选择开始时间");
                        return false;
                    }
                    if($('#e_d').val() == ''){
                        alert("请选择结束时间");
                        return false;
                    }
                };
                var rate ;//折扣率
                if(iskaiqi==1){
                		rate = $('#rate').val();
                }else{
                		rate = 100;
                };
                let s_d = ($('#s_d').val()).replace(/-/g,'/');
                let e_d = ($('#e_d').val()).replace(/-/g,'/');
//                alert("开始时间="+new Date(s_d));
//                alert("开始时间="+new Date(e_d));
                    $.ajax({
                        url: base_url + 'ZITAOHUI/store/discount',
                        data: {
                            store_id: sessionStorage.getItem("s_id"),
                            is_discount_rate: iskaiqi,
                            discount_rate: rate,
                            start_time: s_d,
                            end_time: e_d,
                        },
                        success: function (data) {
                            if (data.code == 1) {
                                window.location.href = '../page/setting-center.html'
                            }
                        },
                        error: function (data) {
                            console.error(data)
                        }
                    })
            })
        })
        function getLocalTime(nS) {

                var now = new Date(nS),
                    y = now.getFullYear(),
                    m = now.getMonth() + 1,
                    d = now.getDate();
//                return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
                return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) ;

        }
    </script>
</body>

</html>